//
//  DriverInfoCell.swift
//  TrafficViolation
//
//  Created by eaglelive on 2017/7/11.
//  Copyright © 2017年 eaglelive. All rights reserved.
//

import Foundation
class DriverInfoCell: UITableViewCell {
    var driveLicense_1,driveLicense_2,submitBtn:UIButton!
    var remark,reason:UITextView!
    var reasonView,okView:UIView!
    var money:UITextField!
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCellSelectionStyle.none
        self.layer.borderWidth = 0

        let carLicense = UILabel.init(frame: CGRect(x: oLabelLeft, y: oTop, width: oLabelW, height: oLabelH))
        carLicense.font = oFontSize
        carLicense.text = "驾驶证信息"
        self.addSubview(carLicense)
        //证件照片
        driveLicense_1 = UIButton.init(frame: CGRect(x: oImgLeft, y: oLabelH + oTop, width: oImgW, height: oImgH))
        driveLicense_1.setBackgroundImage(UIImage(named:"jiashizheng1"), for: .normal)
        self.addSubview(driveLicense_1)
        
        driveLicense_2 = UIButton.init(frame: CGRect(x: oImgLeft, y: oImgH + oLabelH + 2*oTop, width: oImgW, height: oImgH))
        driveLicense_2.setBackgroundImage(UIImage(named:"jiashizheng2"), for: .normal)
        self.addSubview(driveLicense_2)
        
        let remarkLabel = UILabel.init(frame: CGRect(x: oLabelLeft, y: 2*oImgH + oLabelH + 3*oTop, width: oLabelW, height: remarkH))
        remarkLabel.font = oFontSize
        remarkLabel.text = "备注信息"
        self.addSubview(remarkLabel)
        
        remark = UITextView(frame:CGRect(x:oLabelW, y:2*oImgH + oLabelH + 3*oTop, width:oImgW, height:remarkH))
        remark.layer.cornerRadius = 5
        remark.backgroundColor = tableBgColor
        remark.textColor = fontColor
        remark.isEditable = false
        self.addSubview(remark)
        //不可审核时显示
        reasonView = UIView.init(frame:CGRect(x:0, y:2*oImgH + oLabelH + 4*oTop + remarkH, width:kScreenW, height:remarkH))
        reasonView.isHidden = true
        self.addSubview(reasonView)
        
        let reasonLabel = UILabel.init(frame: CGRect(x: oLabelLeft, y:0, width: oLabelW, height: remarkH))
        reasonLabel.font = oFontSize
        reasonLabel.text = "不可办原因"
        reasonView.addSubview(reasonLabel)
        
        reason = UITextView.init(frame:CGRect(x:oLabelW, y:0, width:oImgW, height:remarkH))
        reason.layer.cornerRadius = 5
        reason.backgroundColor = tableBgColor
        reason.textColor = fontColor
        reason.isEditable = false
        reasonView.addSubview(reason)
        //可审核
        okView = UIView.init(frame:CGRect(x:0, y:2*oImgH + oLabelH + 4*oTop + remarkH, width:kScreenW, height:cellH))
        okView.isHidden = true
        self.addSubview(okView)
        
        let moneyLabel = UILabel.init(frame: CGRect(x: oLabelLeft, y:0, width: oLabelW, height: cellH))
        moneyLabel.font = oFontSize
        moneyLabel.text = "服务费"
        okView.addSubview(moneyLabel)
        
        money = UITextField.init(frame: CGRect(x: oLabelW, y:0, width: oImgW, height: cellH))
        money.isEnabled = false
        money.backgroundColor = tableBgColor
        money.textColor = fontColor
        money.font = oFontSize
        money.layer.cornerRadius = 5
        okView.addSubview(money)

        //默认位置：2*oImgH + oLabelH + 5*oTop + remarkH
        submitBtn = UIButton.init(frame: CGRect(x: 20, y: 2*oImgH + oLabelH + 5*oTop + remarkH, width: kScreenW - 40, height: cellH))
        submitBtn.setTitleColor(UIColor.white, for: .normal)
        submitBtn.backgroundColor = appMainColor
        submitBtn.showsTouchWhenHighlighted = true
        submitBtn.layer.cornerRadius = 10
        self.addSubview(submitBtn)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func configCellDateWithModel(_ model:DriverAuditModel) {
        let dic = DriverInfoController()
        driveLicense_1.sd_setBackgroundImage(with: URL.init(string: "\(projectUrl)/file/download/\(model.driveLicense_1)?tokenID=\(tokenID!)&tokenUserID=\(userID!)"), for: .normal)
        driveLicense_2.sd_setBackgroundImage(with: URL.init(string: "\(projectUrl)/file/download/\(model.driveLicense_2)?tokenID=\(tokenID!)&tokenUserID=\(userID!)"), for: .normal)
        remark.text = model.remark
        if model.oprocess.isEmpty {
            submitBtn.setTitle("等待审核", for: .normal)
            submitBtn.isEnabled = false
            submitBtn.backgroundColor = UIColor.lightGray
        }else {
            if "0" == model.oprocess {//不可审核
                submitBtn.frame.origin.y = 2*oImgH + oLabelH + 6*oTop + 2*remarkH
                reasonView.isHidden = false
                reason.text = model.reason
                submitBtn.setTitle("不可审", for: .normal)
                submitBtn.isEnabled = false
                submitBtn.backgroundColor = UIColor.lightGray
            }
            if "1" == model.oprocess {//可审核
                submitBtn.frame.origin.y = 2*oImgH + oLabelH + 6*oTop + remarkH + cellH
                okView.isHidden = false
                money.text = model.samount
                if "0" ==  model.ostatus{
                    submitBtn.setTitle("去支付", for: .normal)
                    submitBtn.tag = 0
                    submitBtn.addTarget(dic, action: #selector(dic.operatorFun(sender:)), for: UIControlEvents.touchUpInside)
                }
                if "1" == isEmployee {//普通用户登录
                    if "1" == model.ostatus {
                        submitBtn.setTitle("等待处理", for: .normal)
                        submitBtn.isEnabled = false
                        submitBtn.backgroundColor = UIColor.lightGray
                    }
                    if "2" == model.ostatus {
                        submitBtn.setTitle("处理中", for: .normal)
                        submitBtn.backgroundColor = UIColor.lightGray
                        submitBtn.isEnabled = false
                    }
                    if "3" == model.ostatus {
                        submitBtn.setTitle("已处理", for: .normal)
                        submitBtn.isEnabled = false
                        submitBtn.backgroundColor = UIColor.lightGray
                    }
                }
                if "2" == isEmployee {
                    if "1" == model.ostatus {
                        submitBtn.setTitle("抢单", for: .normal)
                        submitBtn.tag = 1
                        submitBtn.addTarget(dic, action: #selector(dic.operatorFun(sender:)), for: UIControlEvents.touchUpInside)
                    }
                    if "2" == model.ostatus {
                        submitBtn.setTitle("完成", for: .normal)
                        submitBtn.tag = 2
                        submitBtn.addTarget(dic, action: #selector(dic.operatorFun(sender:)), for: UIControlEvents.touchUpInside)
                    }
                    if "3" == model.ostatus {
                        submitBtn.setTitle("已完成", for: .normal)
                        submitBtn.backgroundColor = UIColor.lightGray
                        submitBtn.isEnabled = false
                    }
                }
            }
        }
    }
}
